﻿import odal.*;
class odal.OMSRelation extends OMSNode {
	private var m_sourceElement:OMSElement;
	private var m_aTargetElements:Array;
	private var m_TargetElementsById:Object;
	private var m_TargetElementsByRelationId:Object;
	private var m_TargetElementsByKey:Object;

	public function OMSRelation( sourceElement:OMSElement, targetElement:OMSElement, catName:String, type:String, relId:String, key:String ){
		this.m_TargetElementsById = new Object();
		this.m_TargetElementsByRelationId = new Object();
		this.m_TargetElementsByKey = new Object();
		this.m_aTargetElements = new Array();
//		trace '[OMSRelation->OMSRelation]';
		this.m_sourceElement = sourceElement;
		this.m_id = catName;
		this.m_name = type;
		this.addElement2Relation( targetElement, relId, key );
	}//OMSRelation
	
	function get TargetElements():Array {
//		trace ( '[OMSRelation.get TargetElements] this.m_id: ' + this.m_id + ' - this.m_aTargetElements.length: ' + this.m_aTargetElements.length );
//		trace ( '[OMSRelation.get TargetElements] *********** Content of m_aTargetElements *******************' );
//		for ( var i:String in this.m_aTargetElements ) {
//			trace( '[OMSRelation.get TargetElements] Id: ' + this.m_aTargetElements[ i ].Id + ' - Name: ' + this.m_aTargetElements[ i ].Name );
//		}//for
//		trace ( '[OMSRelation.get TargetElements] *********** END Content of m_aTargetElements *******************' );
		return this.m_aTargetElements;
	}//get TargetElements
	
	public function get SourceElement():OMSElement {
		return this.m_sourceElement;
	}//get SourceElement
	
	public function get IsComposition():Boolean {
		var bRet:Boolean = false;
		if ( this.m_name == 'c' ) {
			bRet = true;
		}//if
		return bRet;
	}//get IsComposition

	public function get IsAssociation():Boolean {
		var bRet:Boolean = false;
		if ( this.m_name == 'a' ) {
			bRet = true;
		}//if
		return bRet;
	}//get IsComposition

	public function addElement2Relation( targetElement:OMSElement, relId:String, key:String ):Void {
		this.m_aTargetElements.push( targetElement );
		this.m_TargetElementsById[ targetElement.Id ] = targetElement;
		this.m_TargetElementsByRelationId[ relId ] = targetElement;
		this.m_TargetElementsByKey[ key ] = targetElement;
	}//addElement2Relation

}//odal.OMSRelation 